package com.ffyc.ssm.controller;

import com.ffyc.ssm.common.CommonResult;
import com.ffyc.ssm.modle.User;
import com.ffyc.ssm.service.UserService;
import com.ffyc.ssm.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping(path = "/userInterface")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(path = "/saveUpdate")
    public CommonResult saveUpdateInfo(HttpSession session, User user) {
        CommonResult commonResult = null;

        try {
            System.out.println(user);
            userService.saveUpdateInfo(user);
            commonResult = new CommonResult(200, "保存成功", null);
        } catch (Exception exception) {
            exception.printStackTrace();
            commonResult = new CommonResult(500, "查询失败", null);
        }
        return commonResult;
    }

    @RequestMapping(path = "/selectPassword")
    public CommonResult selectPassword(String password,Integer id) {
        CommonResult commonResult = null;
        try {
            User user= userService.selectPassword(password,id);
            if (user!=null){
                commonResult = new CommonResult(200, "密码正确", null);
            }else {
                commonResult = new CommonResult(300, "密码正确", null);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            commonResult = new CommonResult(500, "查询失败", null);
        }
        return commonResult;
    }

    @RequestMapping(path = "/saveNewPwd")
    public CommonResult saveNewPwd(String password,Integer id) {
        CommonResult commonResult = null;

        try {

            userService.saveNewPassword(password,id);
            commonResult = new CommonResult(200, "保存成功", null);
        } catch (Exception exception) {
            exception.printStackTrace();
            commonResult = new CommonResult(500, "查询失败", null);
        }
        return commonResult;
    }
}
